<!--
 * @FileDescription 点云呈现
 * @Author 杨宇翔
 * @Date 20220714 10:39:37
 * @LastEditors 杨宇翔
 * @LastEditTime 20220714 10:39:37
-->
<template>
    <div class="scan" v-show="UseComponent.Default.Choice.value == '激光扫描'">
        <i></i>
        <button class="reset" type="button" @click="OnChanged">
            <img
                :src="state ? `/static/Lidar/ic_zhankai.png` : `/static/Lidar/ic_shouqi.png`">
            <span>激光扫描</span>
        </button>
        <div class="row">
            <span>视场角</span>
            <input class="reset" type="number" v-model="startAngle" min="0" max="360" step="1"
                @keyup.enter="startAngle = Math.clamp(startAngle, 0, endAngle); OnSubmitAsync();">
            <span>—</span>
            <input class="reset" type="number" v-model="endAngle" min="0" max="360" step="1"
                @keyup.enter="endAngle = Math.clamp(endAngle, startAngle, 360); OnSubmitAsync();">
        </div>

        <div class="row">
            <span>转速</span>
            <UseDropdown class="speed" :Options="options" v-model="speed" />
        </div>

        <span>点云设置</span>
        <div class="row">
            <span>点半径</span>
            <input class="reset" type="number" v-model="radius" min="0" max="1" step="0.01"
                @keyup.enter="radius = Math.clamp(radius, 0, 1); OnSubmitAsync();">
        </div>
        <div class="row">
            <input type="checkbox" hidden name="激光扫描" id="distance" value="distance" checked>
            <label for="distance">
                <img src="/static/Lidar/ic_radio_normal.png">
                <span>点距离</span>
            </label>
        </div>

        <div class="row">
            <template v-for="distance of distances" :key="distance">
                <span class="material-icons">square</span>
                <span>{{ distance }}</span>
            </template>
        </div>

        <span>操作说明</span>

        <button class="reset key" type="button">
            <span>W</span>
            <span>前进</span>
        </button>
        
        <div class="key-container">
            <button class="reset key" type="button">
                <span>A</span>
                <span>左转</span>
            </button>
            <button class="reset key" type="button">
                <span>S</span>
                <span>后退</span>
            </button>
            <button class="reset key" type="button">
                <span>D</span>
                <span>右转</span>
            </button>
        </div>

        <button class="reset key" type="button" style="margin-top: -10px; width: 200px">
            <span>Space</span>
            <span>刹车</span>
        </button>
    </div>
</template>

<script setup lang="ts">
import { ClientMessage } from '@runtime/generate/message/ClientMessage';
import { UseComponent } from './LidarComponent';
import UseDropdown from './UseDropdown.vue';
import { Ref, ref, watch } from 'vue';
import WebSocketComponent from '@runtime/module/WebSocket/WebSocketComponent';

const options = new Map<number, string>([
    [300, '300转/分钟'],
    [600, '600转/分钟'],
    [1200, '1200转/分钟'],
]);

const speed = ref(600);

const choices: Ref<Array<string>> = ref([]);
watch(choices, () => {
    if (choices.value.length > 1) {
        choices.value.removeAt(0);
    }
});

const startAngle = ref(0);
const endAngle = ref(360);
const radius = ref(0.1);

watch(speed, OnSubmitAsync);

async function OnSubmitAsync(): Promise<void> {
    console.log(`${startAngle.value}-${endAngle.value} ${speed.value} ${radius.value}`);
    await WebSocketComponent.Default.PostMessageAsync(new ClientMessage.LaserRadarScanSettingsRequest(startAngle.value,endAngle.value,speed.value,radius.value));     
}

const distances = ['200米', '100米', '50米', '30米', '20米', '10米'];

const state = ref(true);

const sidebarTranslateX = ref('translateX(0)');
const buttonTranslateX = ref('translateX(0)');

function OnChanged() {
    state.value = !state.value;
    sidebarTranslateX.value = state.value ? 'translateX(0)' : 'translateX(100%)';
    buttonTranslateX.value = state.value ? 'translateX(0)' : 'translateX(-6rem)';
}
</script>

<style scoped>
.scan {
    position: absolute;
    top: 8rem;
    right: 0;

    padding-bottom: 2rem;

    border-radius: 2rem 0 0 2rem;
    background-color: #131620;

    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2rem;

    transform: v-bind(sidebarTranslateX);

    transition: transform 300ms;
}

.scan>span {
    display: inline-block;
    width: calc(100% - 0.6rem);
    height: 5rem;

    margin-left: 0.6rem;

    box-shadow: inset 0 -0.1rem 0 0 #1F1F2D;

    color: #B1B1D4;
    font-size: 1.8rem;
    text-indent: 2rem;
    line-height: 5rem;
}

i {
    position: absolute;
    left: 0;
    bottom: 0;

    display: block;
    width: 100%;
    height: calc(100% - 5rem);

    border-left: solid 0.6rem transparent;
    border-bottom: solid 0.6rem transparent;
    border-radius: 0 0 0 2rem;
    background-image: linear-gradient(#131620, #131620),
        linear-gradient(90deg, #218cde, #807de1);
    background-origin: border-box;
    background-clip: content-box, border-box;

    z-index: -1;
}


.scan>button:first-of-type {
    width: 100%;
    height: 5rem;

    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 1.4rem;

    padding-left: 2.4rem;

    background-color: #131620;

    border-radius: 2.5rem 0 0 2.5rem;
    box-shadow: inset 0 -0.1rem 0 0 #1F1F2D;

    transform: v-bind(buttonTranslateX);

    transition: transform 300ms;
}


.scan>button:first-of-type>span:first-of-type {
    color: #B1B1D4;
    font-size: 1.8rem;
    font-weight: 500;
}

.row {
    max-width: 30rem;

    /* margin-left: 2rem; */
    padding-left: 2rem;

    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.row>span,
.row>label>span {
    color: #81859C;
    font-size: 1.6rem;
}

.row>label {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.row:nth-of-type(2)>span {
    min-width: 5rem;
}

.row>input {
    width: 8rem;
    height: 3.6rem;

    color: #B1B1D4;
    font-size: 1.8rem;
    text-align: center;

    border: 0.1rem solid #36384B;
}

.row>input:focus {
    border: solid 0.1rem;
    border-image: linear-gradient(90deg, rgba(128, 125, 225, 1), rgba(33, 140, 222, 1)) 1 1;
}

.row:nth-of-type(3)>input,
.row:nth-of-type(4)>input {
    width: 20rem;
}

.row:nth-of-type(4) {
    width: calc(100% - 4rem);
    justify-content: space-between;
}

.row>input:checked+label>img {
    content: url('/static/Lidar/ic_radio_select.png');
}

.row:nth-of-type(5) {
    align-self: center;
    display: grid;
    grid-template-columns: repeat(3, 1.6rem 5rem);
}

.row:nth-of-type(5)>span:nth-of-type(1) {
    color: #4B3ACF;
}

.row:nth-of-type(5)>span:nth-of-type(3) {
    color: #9B2FE0;
}

.row:nth-of-type(5)>span:nth-of-type(5) {
    color: #EB984B;
}

.row:nth-of-type(5)>span:nth-of-type(7) {
    color: #CDD23D;
}

.row:nth-of-type(5)>span:nth-of-type(9) {
    color: #3FDBBD;
}

.row:nth-of-type(5)>span:nth-of-type(11) {
    color: #BD53A3;
}

.speed {
    width: 20rem;
}

.key {
    width: 6rem;
    height: 5rem;

    border-radius: 0.6rem;
    background-color: #36384B;

    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.key>span:first-of-type {
    color: white;
    font-size: 1.4rem;
}

.key>span:last-of-type {
    color: #B1B1D4;
    font-size: 1.4rem;
}

.scan>.key {
    align-self: center;
}

.key-container {
    align-self: center;

    margin-top: -1rem;

    display: flex;
    align-items: center;
    gap: 1rem;
}               
</style>./LidarComponent